package com.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.Dao.UserDao;
import com.google.gson.Gson;
import com.pojo.User;

@WebServlet("/procCtry")
public class ProcController3 extends HttpServlet {
	private static final long serialVersionUID = 1L;
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		
		request.setCharacterEncoding("utf-8");	
		response.setCharacterEncoding("utf-8");
		Integer Uid= Integer.valueOf(request.getParameter("Uid"));
		String Uname = request.getParameter("Uname");
		String Usex = request.getParameter("Usex");
		String Uage = request.getParameter("Uage");
		String Uemail = request.getParameter("Uemail");
		String Uhome = request.getParameter("Uhome");
		UserDao userDao = new UserDao();
		User user = new User(Uid,Uname,Usex,Uage,Uemail,Uhome);
	//3������UserDao����
		try {
			userDao.Updateinventory(Uid,Uname,Usex,Uage,Uemail,Uhome);
		} catch (SQLException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
		}
		User userx = null;
		try {
			userx = userDao.findUserByUserx(user);
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		Gson gson = new Gson();
		String jsonStr = gson.toJson(userx);
		PrintWriter out = response.getWriter();
		out.print(jsonStr);
	}
}
